
	** Urban / rural status across waves
		
		use "$dir/rawdata/GSPS Ghana/Waves 123/w123_HH_comm_link_KL_v2.dta", clear
		isid FPrimary wave
		keep wave FPrimary urbrur
		ren FPrimary hhid
		destring hhid, replace
		ren wave wave_temp
		gen wave="w1" if wave_temp==1
		replace wave="w2" if wave_temp==2
		replace wave="w3" if wave_temp==3
		replace urbrur=0 if urbrur==2
		drop wave_temp
		tempfile urbrur
		save `urbrur', replace
		
	** Individual waves
	
		use "$dir/data/gha_w1_individual.dta", clear
		ren w1_* *
		gen wave="w1"
		tempfile data
		save `data', replace
		
		qui foreach wave in w2 w3 {
			use "$dir/data/gha_`wave'_individual.dta", clear
			ren `wave'_* *
			gen wave="`wave'"
			append using `data'
			save `data', replace
		}
		
	** Age groups
		replace age=. if age<0
		gen age_group5=floor(age/5)*5
		gen age_group10=floor(age/10)*10
		
		replace age_group5=80 if age_group5>80 & !missing(age_group5)
		replace age_group10=80 if age_group10>80 & !missing(age_group10)
		
	** Merge in urban status
	
		merge m:1 hhid wave using `urbrur', gen(merge_urbrur) assert(master matched)
		assert urban==urbrur if !missing(urban) // matches well for wave 1
		replace urban=urbrur if missing(urban)
		
	/*
	** Any work
		egen work_any=rowmax(work_primary work_secondary work_enterprise)
		replace work_any=0 if missing(work_any) // FIXME: This isn't great
	
		egen work_hrs=rowtotal(work_primary_hrs work_secondary_hrs work_enterprise_hrs)
		*/
		
	** Lives alone
		gen lives_alone=(hh_size==1)		

		save "$dir/data/gha.dta", replace

		